package com.appkubes.fintech.restful.application.risk.data.xingpan.http;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

public class ReturnStringResponseHandler implements ResponseHandler<String> {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    public ReturnStringResponseHandler() {
    }

    @Override
    public String handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
        HttpEntity entity = response.getEntity();
        String s = EntityUtils.toString(entity, "UTF-8");
        logger.info("Response status = {}", response.getStatusLine().getStatusCode());
        logger.info("Response content = {}", s);
        return s;
    }
}
